package com.pro.api;


import com.pro.bean.Img;
import com.pro.dto.Dto;
import com.pro.service.ImgService;
import com.pro.util.dtoUtil.DtoUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Img)表控制层
 *
 * @author makejava
 * @since 2020-12-29 12:02:27
 */
@RestController
@RequestMapping("img")
public class ImgController {
    /**
     * 服务对象
     */
    @Resource
    private ImgService imgService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Img selectOne(Integer id) {
        return this.imgService.queryById(id);
    }

    //查询所有
    @GetMapping("all")
    public Dto all(){
        return DtoUtil.returnSuccess(imgService.all());
    }

    //增加
    @PostMapping("insert")
    public Dto insert(@RequestBody Img img){
        if (imgService.insert(img) > 0){
            return DtoUtil.returnSuccess(imgService.insert(img));
        }else {
            return DtoUtil.returnError(5001,"插入失败");
        }


    }

    //修改
    @PostMapping("update")
    public Dto update(@RequestBody Img img){
        if (imgService.update(img) > 0){
            return DtoUtil.returnSuccess();
        }else {
            return DtoUtil.returnError(5001,"失败");
        }
    }

    //删除
    @GetMapping("deleteById")
    public Dto deleteById(Integer id){
        if (imgService.deleteById(id) > 0){
            return DtoUtil.returnSuccess();
        }else {
            return DtoUtil.returnError(5001,"失败");
        }
    }


}